/**
 * 扫描文件返回指定接口的路径
 */
import * as fs from 'fs';
import * as path from 'path';

const join = path.join;

export interface FilePathMode {
    absolutePath?: string;
    filename?: string;
}

export default (rootPath: string): FilePathMode[] => {
    const result: FilePathMode[] = [];
    const scan = (path: string): void => {
        fs.readdirSync(path).forEach((f) => {
            const fpath: string = join(path, f);
            if (fs.statSync(fpath).isDirectory()) {
                scan(fpath);
            } else {
                result.push({
                    filename: f.split('.')[0],
                    absolutePath: fpath
                });
            }
        });
    };
    scan(rootPath);
    return result;
};